package com.qf.listener;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardSubmit;
import com.qf.serivice.ElasticSearchService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * projectName: sms-platform02
 *
 * @author: 元
 * time: 2021/10/21 0021 15:00
 * description:搜索模块监听器
 */
@Component
@Slf4j
public class SendLogListener {

    @Autowired
    private ElasticSearchService elasticSearchService;

    @RabbitListener(queues = RabbitMQConstants.TOPIC_SMS_SEND_LOG)
    public void consume(StandardSubmit standardSubmit, Channel channel, Message message) throws IOException{

        //保存短信对象到ES服务器中
        elasticSearchService.saveLog(standardSubmit);


        //手动ACK确认
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }
}
